<?php
	session_start();
	if(!isset($_POST['inputDate']) || !isset($_POST['outputDate'])){
		if(!isset($_POST['inputDate2']) || !isset($_POST['outputDate2']))
			header('Location: bookroom.php');
	}
	require_once("database.php");
	$link = connectDB();
	$inputDate = isset($_POST['inputDate'])?$_POST['inputDate']:$_POST['inputDate2'];
	$outputDate = isset($_POST['outputDate'])?$_POST['outputDate']:$_POST['outputDate2'];
	$currentDate = time();
	if($currentDate > strtotime($inputDate) || strtotime($inputDate)>strtotime($outputDate)) {
		$_SESSION['error']['time'] = "Nhập thời gian không hợp lệ";
		header('Location: bookroom.php');
	}
	$_SESSION['inputDate'] = $inputDate;
	$_SESSION['outputDate'] = $outputDate;
	$inputDate = date('Y-m-d',strtotime($inputDate));
	$outputDate = date('Y-m-d',strtotime($outputDate));
	$sql = "UPDATE bookingroom SET status = 1 WHERE startTime < now()";
	mysql_query($sql,$link);
	$sql="	SELECT room.id
			,room.serviceId
			,vn AS roomName
			,roomNo
			,quantity
			,floorPrice
			,ceilingPrice
			,additionalServices FROM room
			,services 
			WHERE room.serviceId = services.id
			and room.id not in (select unitId
								from bookingroom
								where status =0
								and (
									(startTime<='$inputDate' and finishTime >= '$inputDate')
									or (startTime<='$outputDate' and finishTime >= '$outputDate')
									or (startTime>='$inputDate' and finishTime <= '$outputDate')
								))";
	$result = mysql_query($sql,$link);
	
	include_once('header.php'); 
	function check_lang() { 
	if(isSet($_GET['lang']))
	{
		$lang = $_GET['lang'];
		
		// register the session and set the cookie
		$_SESSION['lang'] = $lang;
		
	}
	else if(isSet($_SESSION['lang']))
	{
		$lang = $_SESSION['lang'];
	}
	else if(isSet($_COOKIE['lang']))
	{
		$lang = $_COOKIE['lang'];
	}
	else
	{
		$lang = 'en';
	}
	
	//directory name 
	  $dir = 'languages'; 
	
	//no we return the langauge wanted ! 
	//Returned String Format: dirname/filename.ext 
	  return "$dir/$lang.lng"; 
} 
?>
	<?PHP
	//this function will check user language and return the file name to be included .. 
	$lang = check_lang();
	$_SESSION['abc'] = 'room1';
	include($lang); 
	?>
	<div id="wrapper1">
		<!-- Header : ---------------------  Start -------------------------
			Describle : banner + logo + search + link (english, vietnam, rss)-->	
		<div id="header" class="container" align="center">
			<!-- text link -->
			<div style="float:left; margin:40px 30px auto; font-size:18px; color:#666666">
				<b> Site map | 
				<a onclick="developfunction('')" id="english" 
					onmouseover="change_color_link('english', '#000000')" 
					onmouseout="change_color_link('english', '#666666')"
					href="checkroom.php?lang=en" > 
						English </a> | 
				<a onclick="refreshView()" id="vietnam" 
					onmouseover="change_color_link('vietnam', '#000000')" 
					onmouseout="change_color_link('vietnam', '#666666')"
					href="checkroom.php?lang=vn"> 
						Vietnam </a> | 
				<a id="rss" onclick="developfunction('')"
					onmouseover="change_color_link('rss', '#000000')" 
					onmouseout="change_color_link('rss', '#666666')"
					> 
						RSS </a></b>			</div>
			
<?php include_once('menu.php'); ?>
<?php
	
	
	
	echo '<table width="700px" cellpadding="0" cellspacing="0" border="0" class="display" id="example">
			<thead>
				<tr>
					<th>Room name </th>
					<th>Room no </th>
					<th>Quantity</th>
					<th>Floor price</th>
					<th>Ceiling price  </th>
					<th>Services</th>
					<th>Delete</th>
				</tr>
			</thead><tbody>';
	while ($row = mysql_fetch_assoc($result)) {
		echo '<tr class="gradeC">';
		echo '<td><a href="viewdetail.php?id='.$row['id'].'&serviceid='.$row['serviceId'].'">'.$row['roomName'].'</a></td>';
		echo '<td>'.$row['roomNo'].'</td>';
		echo '<td>'.$row['quantity'].'</td>';
		echo '<td>'.$row['floorPrice'].'</td>';
		echo '<td>'.$row['ceilingPrice'].'</td>';
		echo '<td>'.$row['additionalServices'].'</td>';
		echo '<td align="center"><a href="bookinfo.php?id='.$row['id'].'">Đặt phòng </a></td>';
		echo '</tr>';
	}
	mysql_free_result($result);
	
	echo '</tbody></table>';?>
<?php include_once('footer.php'); ?>